/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.uncopt.ohos.example.justify.slice;

import com.uncopt.ohos.example.justify.MainProvider;
import com.uncopt.ohos.example.justify.ResourceTable;
import com.uncopt.ohos.widget.text.justify.utils.PreferenceUtils;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.PageSlider;
import ohos.agp.window.service.WindowManager;

public class MainAbilitySlice extends AbilitySlice {
    private PageSlider mPagerSlider;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        getWindow().setInputPanelDisplayType(WindowManager.LayoutConfig.INPUT_ADJUST_PAN);

        mPagerSlider = (PageSlider) findComponentById(ResourceTable.Id_page_slider);
        MainProvider mainProvider = new MainProvider(this);
        mPagerSlider.setProvider(mainProvider);

        Component guidLayout = findComponentById(ResourceTable.Id_help);

        findComponentById(ResourceTable.Id_ok).setClickedListener(component -> {
            guidLayout.setVisibility(Component.HIDE);
            PreferenceUtils.putGuidanceChart(MainAbilitySlice.this,
                    PreferenceUtils.PREFERENCE_FILE_NAME, true);
        });

        if (PreferenceUtils.getGuidanceChart(this, PreferenceUtils.PREFERENCE_FILE_NAME)) {
            guidLayout.setVisibility(Component.HIDE);
        } else {
            guidLayout.setVisibility(Component.VISIBLE);
        }
    }


    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
